package com.dkd.system.service.impl;

import java.util.List;

import com.dkd.common.constant.DkdContants;
import com.dkd.common.utils.DateUtils;
import com.dkd.system.domain.TbRegion;
import com.dkd.system.domain.TbRole;
import com.dkd.system.domain.TbVendingMachine;
import com.dkd.system.mapper.TbRegionMapper;
import com.dkd.system.mapper.TbRoleMapper;
import com.dkd.system.mapper.TbVendingMachineMapper;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.dkd.system.mapper.TbEmpMapper;
import com.dkd.system.domain.TbEmp;
import com.dkd.system.service.ITbEmpService;

import javax.annotation.Resource;
import javax.swing.plaf.synth.Region;

/**
 * 工单员工Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-03-27
 */
@Service
public class TbEmpServiceImpl implements ITbEmpService 
{
    @Autowired
    private TbEmpMapper tbEmpMapper;
@Resource
private TbRegionMapper tbRegionMapper;
@Resource
private TbRoleMapper tbRoleMapper;
@Resource
private TbVendingMachineMapper tbVendingMachineMapper;
    /**
     * 查询工单员工
     * 
     * @param id 工单员工主键
     * @return 工单员工
     */
    @Override
    public TbEmp selectTbEmpById(Long id)
    {
        return tbEmpMapper.selectTbEmpById(id);
    }

    /**
     * 查询工单员工列表
     * 
     * @param tbEmp 工单员工
     * @return 工单员工
     */
    @Override
    public List<TbEmp> selectTbEmpList(TbEmp tbEmp)
    {
        return tbEmpMapper.selectTbEmpList(tbEmp);
    }
@Override
public   TbEmp selectEmpById(Long userId){
    return tbEmpMapper.selectTbEmpById(userId);
}
    /**
     * 新增工单员工
     * 
     * @param tbEmp 工单员工
     * @return 结果
     */
    @Override
    public int insertTbEmp(TbEmp tbEmp)
    {
TbRegion region= tbRegionMapper.selectTbRegionById(tbEmp.getRegionId());
tbEmp.setRegionName(region.getRegionName());
TbRole tbRole=tbRoleMapper.selectTbRoleByRoleId(tbEmp.getRoleId());
tbEmp.setRoleName(tbRole.getRoleName());
tbEmp.setRoleCode(tbRole.getRoleCode());
tbEmp.setCreateTime(DateUtils.getNowDate());
        return tbEmpMapper.insertTbEmp(tbEmp);
    }

    /**
     * 修改工单员工
     * 
     * @param tbEmp 工单员工
     * @return 结果
     */
    @Override
    public int updateTbEmp(TbEmp tbEmp)
    {
        TbRegion region= tbRegionMapper.selectTbRegionById(tbEmp.getRegionId());
        tbEmp.setRegionName(region.getRegionName());
        TbRole tbRole=tbRoleMapper.selectTbRoleByRoleId(tbEmp.getRoleId());
        tbEmp.setRoleName(tbRole.getRoleName());
        tbEmp.setRoleCode(tbRole.getRoleCode());
        tbEmp.setUpdateTime(DateUtils.getNowDate());
        return tbEmpMapper.updateTbEmp(tbEmp);
    }

    /**
     * 批量删除工单员工
     * 
     * @param ids 需要删除的工单员工主键
     * @return 结果
     */
    @Override
    public int deleteTbEmpByIds(Long[] ids)
    {
        return tbEmpMapper.deleteTbEmpByIds(ids);
    }

    @Override
    public     List<TbEmp> selectbyinnercode(String innerCode){
        TbVendingMachine tbVendingMachine=tbVendingMachineMapper.getbyinnercode(innerCode);
        TbEmp tbEmp=new TbEmp();
        tbEmp.setRegionId(tbVendingMachine.getRegionId());
        tbEmp.setStatus(1);
        tbEmp.setRoleCode(DkdContants.ROLE_CODE_BUSINESS);
        List<TbEmp> list=tbEmpMapper.selectTbEmpList(tbEmp);
        return list;

    }
   public List<TbEmp> selectbyinnercode1(String innerCode){
       TbVendingMachine tbVendingMachine=tbVendingMachineMapper.getbyinnercode(innerCode);
       TbEmp tbEmp=new TbEmp();
       tbEmp.setRegionId(tbVendingMachine.getRegionId());
       tbEmp.setStatus(1);
       tbEmp.setRoleCode(DkdContants.ROLE_CODE_OPERATOR);
       List<TbEmp> list=tbEmpMapper.selectTbEmpList(tbEmp);
       return list;

   }
    /**
     * 删除工单员工信息
     * 
     * @param id 工单员工主键
     * @return 结果
     */
    @Override
    public int deleteTbEmpById(Long id)
    {
        return tbEmpMapper.deleteTbEmpById(id);
    }
}
